﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Showroom.BLL;
using System.Data;

namespace MobileWeb
{
    public partial class GetProducts : System.Web.UI.Page
    {
        private int CategoryID
        {
            get
            {
                return string.IsNullOrEmpty(Request["catid"]) ? 0 : Convert.ToInt32(Request["catid"]);
            }
        }

        private int Page
        {
            get
            {
                return string.IsNullOrEmpty(Request["page"]) ? 0 : Convert.ToInt32(Request["page"]);
            }
        }

        private int PageSize
        {
            get
            {
                return string.IsNullOrEmpty(Request["size"]) ? 0 : Convert.ToInt32(Request["size"]);
            }
        }

        protected string ListProducts = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                View_ListProducts cProds = new View_ListProducts();
                string filter = string.Format("{0} = {1}", View_ListProducts.ColumnNames.CategoryID, CategoryID);
                cProds.Search(filter, View_ListProducts.ColumnNames.ID + " DESC", Page * PageSize, PageSize);

                string sRender = string.Empty;

                for (int i = 0; i < cProds.RowCount; i++)
                {
                    sRender += string.Format("<li style=\"cursor: pointer;\"><img width=\"90\" height=\"90\" title=\"{0}\" alt=\"{0}\" src=\"{1}\" itemprop=\"image\" /><h3><a href=\"{3}\"><p class=\"truncate\" style=\"max-height: none;\">{0}</p></a></h3><div><span class=\"price\">{2}</span></div></li>",
                        cProds.s_Name,
                        Utilities.GetKeySetting("PCHost") + "/" + Utilities.GetKeySetting("PathUploadImageThumb") + "/" + cProds.s_ImageUrl,
                        string.IsNullOrEmpty(cProds.s_Price) || Convert.ToDecimal(cProds.s_Price) == Convert.ToDecimal("0") ? "" : String.Format("{0:C}",
                        cProds.Price),
                        string.Format("ProductDetail.aspx?cid={0}&id={1}", cProds.s_CategoryID, cProds.s_ProductID)
                        );
                    cProds.MoveNext();
                }

                ListProducts = sRender;
            }
        }
    }
}